<?php if (count($pages)): ?>
<?php include_partial('install/terms_wall_form', array()); ?>
<?php
  $install_title = false;
  $admin_title = false;
?>
<?php foreach ($pages as $page_id => $page): ?>
  <?php
    if (!$page['is_admin'] && !$install_title) {
        $install_title = true;
        echo content_tag('h3', __("Which Page do you want to install FSmartShop on?"));
    } elseif ($page['is_admin'] && !$admin_title) {
        $admin_title = true;
        echo content_tag('h3', __("Pages with FSmartShop already installed"));
    }
  ?>
  <a id="page<?php echo $page_id ?>" class="page" <?php
    if ($page['is_admin'])
        echo 'href="'.fb_url_for('@backoffice_list?page_id='.$page_id, true).'" target="_top"';
    elseif ($page['is_added'])
        // echo 'href="'.url_for('@install_step1_save?page_id='.$page_id).'"';
        echo 'href="#" onclick="finishInstall('.$page_id.'); return false;"';
    else
        echo 'href="#" onclick="requestPagePermissions('.$page_id.'); return false;"';
    ?>>
    <?php if ($page['picture']): ?>
		<img class="fleft" width="50" src="<?php
		/* see FS#12061 */
		echo strtr($page['picture'], array('http://profile.ak.fbcdn.net/' => 'https://fbcdn-profile-a.akamaihd.net/','http://static.ak.fbcdn.net/' => 'https://s-static.ak.fbcdn.net/')); ?>" />
	<?php endif ?>
    <span class="link">
        <?php
        if ($page['is_admin'])
            echo __("Go to admin section");
        elseif ($page['is_added'])
            echo __("Finish install");
        else
            echo __("Add to Page");
        ?>
    </span>
    <span class="content">
        <span class="name"><?php echo $page['name'] ?></span>
        <span class="loaderMini" id="loaderMini<?php echo $page_id ?>" style="display:none;vertical-align:baseline;margin-left:2px"></span>
        <br />
        <?php
        if ($page['type'] === 'application')
            echo __("Application");
        else
            echo __("Page");
        ?>
    </span>
  </a>
<?php endforeach ?>
    <p class="text-center">
    <?php echo __("If you want to install the app on a new Page, %link%.", array(
    '%link%' => link_to(content_tag('strong', __("you can create a new Page")),
            'http://www.facebook.com/pages/create.php', array(
                'onclick' => 'trackNewPage()',
                'target'  => '_blank',
            )),
    )) ?>
    </p>
<?php else: ?>
    <div class="message-grey">
    <?php echo __("You do not have a Facebook Page, which is required to install the app.") ?><br /><br />
    <?php echo link_to(content_tag('strong', __('Or your pages dont appear, click here to see them')), 'https://www.facebook.com/add.php?api_key=400951353297880&pages=1', array(
                    'target'  => '_blank',
            )
    ) ?><br /><br />
    <?php echo link_to(content_tag('strong', __("Click here to create one")),
            'http://www.facebook.com/pages/create.php', array(
                'onclick' => 'trackNewPage()',
                'target'  => '_blank',
            )
    ) ?>
    </div>
<?php endif ?>
